/**
 * @file exec.c
 * @brief
 * @author h0rr0rr_drag0n <h0rr0rr_drag0n@vindekapets.ru
 * @date 19 Июль 2010 12:54:37
 *
 * Some code to run osd_cat in child process
 */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <sys/wait.h>
#include "define.h"

#define _XOPEN_SOURCE

int run_osdcat(char * percentage) {
    int fork_retval = 0;
    char cmd[STRLEN] = "\0";

    sprintf(cmd, "%s %s %s %s", DISPLAY, XAUTHORITY, OSD_CMD, percentage);

    fork_retval = fork();
    if (fork_retval == 0) {
        if (!WIFEXITED(system(cmd))) {
            exit(1);
        }
        exit(0);
    }

    if (fork_retval == -1) {
        syslog(LOG_ERR, "Error: fork(): %s", strerror(errno));
        return 1;
    }

    return 0;
}

